<!-- Generated automatically from an XML file of the same name.
     Copyright: Stephen J. Sangwine and Nicolas Le Bihan, 2008-2011.
--><html><head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
   <title>randq :: Functions (Quaternion Toolbox Function Reference)
</title><link rel="stylesheet" href="qtfmstyle.css" type="text/css"></head><body><h1>Quaternion Function Reference</h1><h2>randq</h2>
<p>Uniformly distributed unit quaternions or rotations</p>
<h2>Syntax</h2><p><tt>Y = randq(varargin)</tt></p>
<h2>Description</h2>
<p>
<tt>randq</tt> constructs uniformly distributed quaternions (distributed
uniformly in 4-space). It accepts the same parameters as the MATLAB&reg;
functions <tt>rand</tt> and <tt>randn</tt>.
</p>
<p>
Each quaternion returned is the result of three calls on the MATLAB&reg; function
<tt>rand</tt>, and hence <tt>randv</tt> modifies the state of the
generator used by <tt>rand</tt>.
To initialise the generator or control the choice of generator, use
<tt>rand</tt>.
</p>
<p>
The result will have uniformly distributed axes and Gaussian-distributed
angles. This rather non-intuitive result is discussed by Shoemake (see
reference). If the quaternions supplied by this function are applied to a
constant pure quaternion (e.g. <tt>qi</tt>) using the formula
<tt>conj(S) .* qi .* S</tt>,
the result will be randomly oriented pure quaternions with a uniform
distribution in 3-space: this is what is meant by 'uniformly distributed
rotations' (but note that this result can be obtained more directly with
<tt>randv</tt> (q.v.)).
</p>

<h2>Examples</h2>
<pre>
&gt;&gt; q = randq(2)
 
q = 2x2 quaternion array

&gt;&gt; angle(q)

ans =

    2.0598    2.0802
    1.1229    1.4153

&gt;&gt; abs(q)

ans =

     1     1
     1     1
</pre>
The Gaussian distribution of angles is easily demonstrated:
<pre>
&gt;&gt; q = randq(1e5,1)
 
q = 100000x1 quaternion array
 
&gt;&gt; hist(angle(q), 50)
</pre>
<img src="randq_angle_hist.png">

<h2>See Also</h2>QTFM function: <a href="randv.html">randv</a><br>MATLAB&reg; function: <a href="matlab:doc rand">rand</a><br>
<h2>References</h2><ol><li>Ken Shoemake, 'Uniform random rotations', in David Kirk (ed),
<i>Graphics Gems III</i>, Academic Press, 1992, pp124-132.
</li></ol>
<h4>&copy; 2008-2011 Stephen J. Sangwine and Nicolas Le Bihan</h4><p><a href="license.html">License terms.</a></p></body></html>